<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-xwIntegral-app" th:object="${xwIntegral}">
        <input id="behaviorId" name="behaviorId" th:field="*{behaviorId}"  type="hidden">
        <input name="deptId"  type="hidden"  th:field="*{deptId}" id="treeIds"/>
        <div class="form-group">
            <label class="col-sm-3 control-label">部门名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="deptName" onclick="selectDeptTree()" readonly="true" id="treeNames" th:field="*{deptName}">
            </div>
        </div>

        <!--<div class="form-group">
            <label class="col-sm-3 control-label">积分菜单：</label>
            <div class="col-sm-8">
                <select name="menuId" th:value="*{menuId}" th:with="type=${@type.getTypeName('3')}" class="form-control m-b-none">
                    <option value="">所有</option>
                    <option th:each="menu : ${type}" th:text="${menu.typeName}" th:value="${menu.menuId}"></option>
                </select>
            </div>
        </div>-->

        <div class="form-group">
            <label class="col-sm-3 control-label">奖扣员工姓名：</label>
            <div class="col-sm-8">
                <!--<input   name="jkNames" class="form-control" type="text">-->
                <select id="aa" name="jkNames" class="form-control m-b-none" th:with="jkName=${@jkName.getJkName()}">
                    <option value="">---请选择---</option>
                    <option th:each="jkName : ${jkName}" th:text="${jkName.userName}" th:value="${jkName.userName}"></option>
                </select>
            </div>
        </div>
    </form>
</div>
<div th:include="include::footer"></div>
<script th:src="@{/ajax/libs/select/select2.js}"></script>
<script type="text/javascript">

    /*用户管理-新增-选择部门树*/
    function selectDeptTree() {
        var treeId = $("#treeIds").val();
        var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeIds").val();
        var url = ctx + "integral/xwIntegral/selectIntegralMenuDeptTree/" + deptId;
        var options = {
            title: '选择部门',
            width: "380",
            url: ctx + "integral/xwIntegral/selectIntegralMenuDeptTree/" + deptId,
            callBack: doSubmit2
        };
        $.modal.openOptions(options);
    }
    function doSubmit2(index, layero){
        var body = layer.getChildFrame('body', index);
        $("#treeIds").val(body.find('#treeId').val());
        var deptId = body.find('#treeId').val()
        $.ajax({
            cache : true,
            type : "get",
            url : ctx + "integral/xwIntegral" + "/selectDeptUser/"+deptId, // todo
            /*data : {
                "deptId": deptId
            },*/
            async : false,
            error : function(request) {
                $.modal.alertError("系统错误");
            },
            success : function(data) {
              //  console.log(data)
                $("#aa").html(data);
            }
        });
        $("#treeNames").val(body.find('#treeName').val());
        layer.close(index);
    }


    var prefix = ctx + "integral/xwIntegral"
    $("#form-xwIntegral-app").validate({
        rules:{
            xxxx:{
                required:true,
            },
        }
    });

    function submitHandler() {
        if ($.validate.form()) {
            //$.operate.save(prefix + "/edit", $('#form-xwIntegral-edit').serialize());
            edit();
        }
    }

    function edit() {
        var deptId = $("input[name='deptId']").val();
        var deptName = $("input[name='deptName']").val();
        var behaviorId = $("input[name='behaviorId']").val();
        var behaviorCategory = $("input[name='behaviorCategory']").val();
        var behaviorTitle = $("input[name='behaviorTitle']").val();
        var behaviorContent = $("textarea[name='behaviorContent']").val();
        var shenQingFangShi = $("select[name='shenQingFangShi'] option:selected").val();
        var zuiDuoIntegral = $("input[name='zuiDuoIntegral']").val();
        var zuiShaoIntegral = $("input[name='zuiShaoIntegral']").val();
        var integralFenJi = $("input[name='integralFenJi']").val();
        var status = $("input[name='status']").is(':checked') == true ? 0 : 1;
        var remark = $("textarea[name='remark']").val();
        var menuId = $("select[name='menuId'] option:selected").val();
        $.ajax({
            cache : true,
            type : "POST",
            url : ctx + "integral/xwIntegral" + "/edit",
            data : {
                "deptId": deptId,
                "deptName": deptName,
                "behaviorId":behaviorId,
                "behaviorCategory": behaviorCategory,
                "behaviorTitle": behaviorTitle,
                "behaviorContent": behaviorContent,
                "shenQingFangShi": shenQingFangShi,
                "zuiDuoIntegral": zuiDuoIntegral,
                "zuiShaoIntegral": zuiShaoIntegral,
                "integralFenJi": integralFenJi,
                "remark": remark,
                "status": status,
                "menuId": menuId
            },
            async : false,
            error : function(request) {
                $.modal.alertError("系统错误");
            },
            success : function(data) {
                $.operate.saveSuccess(data);
            }
        });
    }
</script>
</body>
</html>
